package org.schedule.mapper;


import org.apache.ibatis.annotations.*;
import org.schedule.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {

    // 根据 username 查询用户信息
    @Select("SELECT * FROM user WHERE username = #{username}")
    User queryUserInfoByUsername(String username);


    @Select("SELECT * FROM user WHERE id = #{userId}")
    User queryUserInfoByUserId(Integer userId);
    // 插入新的用户信息
    @Insert("INSERT INTO user (username, nickname, password, age, gender, avatar, registertime) " +
            "VALUES (#{username}, #{nickname}, #{password}, #{age}, #{gender}, #{avatar}, #{registertime})")
    @Options(useGeneratedKeys = true, keyProperty = "id") // Automatically set the generated ID
    int insertUser(User user);

    // 根据 username 更新用户信息
    @Update("UPDATE user SET username = #{username}, nickname = #{nickname}, password = #{password}, " +
            "age = #{age}, gender = #{gender}, avatar = #{avatar} " +
            "WHERE id = #{id}")
    int updateUser(User user);

    // 根据 user_id 删除用户信息
    @Delete("DELETE FROM user WHERE id = #{userId}")
    int deleteUserInfo(Integer userId);


    // 根据用户名模糊查询
    List<User> querySalaryInfoListByUsername(String username);

    // 查询全部
    @Select("select * from user")
    List<User> queryUserInfoList();
}
